package com.my.study.jdbc.service.impl;

import com.my.study.jdbc.dao.AccountDao;
import com.my.study.jdbc.entity.Account;
import com.my.study.jdbc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Carlos
 * @version 1.0
 * @Description TODO
 * @date 2021/11/6 18:29
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private AccountDao accountDao;


    @Override
    @Transactional(rollbackFor = Exception.class, value = "transactionManagerOne")
    public void accountMoney(Integer money, String fromName, String toName) {
        accountDao.reduceMoney(new Account(fromName, money));

        int i = 10 / 0;

        accountDao.addMoney(new Account(toName, money));
    }
}
